<!--
 * @Author: your name
 * @Date: 2022-03-14 09:39:17
 * @LastEditTime: 2022-03-14 13:13:01
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\数组去重方式第四种220314.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var geyao = [1, 2, 3, 4, 6, 7, 1, 2, 3, 8, 9]

    function ArrayCommon(arr) {
      //判断是不是数组  不是数组就返回一个false
      if (!Array.isArray(arr)) {
        console.log('这不是一个数组哦')
        return
      }
      let res = [],
        obj = {}
        //如果对象的属性值不存在 就放进去 不然就赋值+1
    for (let i = 0; i < arr.length; i++) {
        if (!obj[arr[i]]) {
       
            res.push(arr[i])
            obj[arr[i]] = 1
            console.log( obj[arr[i]],"obj[arr[i]]")
        } else {
            obj[arr[i]]++
            console.log( obj[arr[i]],"obj[arr[j]]")
        }
    }
    return res


    }

    console.log(ArrayCommon(geyao, 'geyao'))
  </script>
</body>

</html>